package cn.iocoder.yudao.framework.business.eligibility.dao;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.eligibility.pojo.form.EligibilityPackageQueryDTO;
import cn.iocoder.yudao.framework.business.eligibility.pojo.po.EligibilityPackageBaseEntity;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import java.util.List;

/**
 * 用户身份资格套餐 Mapper
 *
 * @author 山野羡民
 */
//@org.apache.ibatis.annotations.Mapper
public interface EligibilityPackageMapper<DO extends EligibilityPackageBaseEntity, QUERY extends EligibilityPackageQueryDTO> extends CoreMapper<DO> {

    @Nonnull
    default CoreQueryWrapper<DO> buildQueryWrapper(QUERY reqVO) {
        CoreQueryWrapper<DO> wrapper = new CoreQueryWrapper<>();
        wrapper.likeIfPresent("name", reqVO.getName());
        wrapper.orderByAsc("sort");
        wrapper.orderByAsc("price");
        wrapper.orderByDesc("id");
        return wrapper;
    }

    default DO selectOne() {
        CoreQueryWrapper<DO> wrapper = new CoreQueryWrapper<>();
        wrapper.orderByAsc("sort");
        wrapper.orderByAsc("price");
        wrapper.orderByDesc("id");
        wrapper.limitN(1);
        return selectOne(wrapper);
    }

    default List<DO> selectList(@Nullable Integer limit) {
        CoreQueryWrapper<DO> wrapper = new CoreQueryWrapper<>();
        wrapper.orderByAsc("sort");
        wrapper.orderByAsc("price");
        wrapper.orderByDesc("id");
        if (limit != null && limit > 0) {
            wrapper.limitN(limit);
        }
        return selectList(wrapper);
    }

}